#include "BoxCreatorRegistrator.h"
#include "BoxCreatorRegistrationException.h"
#include "BoxModelCreator.h"

#include <iostream>

namespace jm4bbx {

	void BoxCreatorRegistrator::registerCreator(const std::string& boxId, 
		BoxModelCreator* creator) {
		
		if (isRegistered(boxId)) {
			std::cerr << "Unique box id is required: " << boxId << std::endl;
			throw BoxCreatorRegistrationException("Unique box id is required!");
		}
		else {
			(creators_)[boxId] = creator;
		}
	}

	BoxModelCreator* BoxCreatorRegistrator::getCreator(
		const std::string& boxId) {
		
		if (!isRegistered(boxId)) {
			std::cerr << "Unknown box id: " << boxId << std::endl;
			throw BoxCreatorRegistrationException("Unknown box id!");
		}
		else {
			return (creators_)[boxId];
		}
	}

	BoxCreatorRegistrator* BoxCreatorRegistrator::getInstance() {
		static BoxCreatorRegistrator instance_;
		return &instance_;
	}

}
